今天介紹的是 Database File Status。
這部份的資料可以從 information_schema.tables
來處理,以下為重要的欄位與說明。
欄位 | 說明 |
---|---|
data_length |
資料大小 |
index_length |
Index大小 |
data_free |
剩餘空間 |
所以一個 table file 的大小 = data_length
+ index_length
+ data_free
。
用掉的大小 = data_length
+ index_length
。
知道這些配合一些告警就能完成了。
SELECT '<tr><td>', table_schema,
'</td><td>',table_name,
'</td><td>', concat(@@datadir, table_schema, '\\', table_name, '.*'),
'</td><td>', Round((data_length + index_length + data_free) / 1024 / 1024 , 1),
'</td><td>', Round((data_length + index_length) / 1024 / 1024 , 1),
'</td><td>', Round((data_free) / 1024 / 1024 , 1),
'</td><td>', CASE WHEN Round((data_length + index_length)/(data_length + index_length + data_free) * 100 , 2) > @CriticalThresholdPCT AND Round((data_length + index_length + data_free) / 1024 / 1024 , 1) > 1 THEN CONCAT('<div class="Critical">', Round((data_length + index_length)/(data_length + index_length + data_free) * 100 , 2),'</div>')
WHEN Round((data_length + index_length)/(data_length + index_length + data_free) * 100 , 2) > @WarningThresholdPCT AND Round((data_length + index_length + data_free) / 1024 / 1024 , 1) > 1 THEN CONCAT('<div class="Warning">', Round((data_length + index_length)/(data_length + index_length + data_free) * 100 , 2),'</div>')
ELSE CONCAT('<div class="Healthy">', Round((data_length + index_length)/(data_length + index_length + data_free) * 100 , 2),'</div>') END,
'</td></tr>'
FROM information_schema.tables where table_schema not in ('performance_schema', 'mysql', 'information_schema')
order by table_schema, table_name;